﻿using System;
using System.Collections;
using System.Configuration;
using System.Data;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using BOHVote.BLL;

namespace BOH.AccreditationSystem
{
    public partial class ApplyInterviewSet : System.Web.UI.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            if (!IsPostBack)
            {
                bindTime();
                if (Request.QueryString["ID"] != null && Session["ApplyPeriod"] != null)
                {
                    butPrint.OnClientClick = "ShowPrintPage('" + Request.QueryString["ID"].ToString() + "')";
                    FillForm(Request.QueryString["ID"].ToString(), (string)Session["ApplyPeriod"]);

                }
            }
        }

        public void FillForm(string ID,string ApplyPeriod)
        {
            DataSet dst = ApplyClass.dstApplyInterview(ID, ApplyPeriod);
            if (dst.Tables.Count > 0 && dst.Tables[0].Rows.Count>0)
            {
                labApplyName.Text = dst.Tables[0].Rows[0]["Apply_Name"].ToString();
                labApplyPrint.Text = dst.Tables[0].Rows[0]["ApplyPrintID"].ToString();
                drpInteviewMonth.SelectedValue = dst.Tables[0].Rows[0]["InterView_Month"].ToString();
                drpInteviewday.SelectedValue = dst.Tables[0].Rows[0]["InterView_Day"].ToString();
                drpHH.SelectedValue = dst.Tables[0].Rows[0]["interview_TimeHH"].ToString();
                drpMM.SelectedValue = dst.Tables[0].Rows[0]["interview_TimeMM"].ToString();
            }
        }


        public void SaveInterviewTime()
        {
            if (Request.QueryString["InterviewID"] != null && Request.QueryString["InterviewID"].ToString() != "")
            {
                ApplyClass.UpdateInterview(Request.QueryString["ID"].ToString(), Request.QueryString["InterviewID"].ToString(), (string)Session["ApplyPeriod"], drpInteviewMonth.SelectedValue, drpInteviewday.SelectedValue, drpHH.SelectedValue, drpMM.SelectedValue);
            }
            else
            {
                ApplyClass.SaveInterview(Request.QueryString["ID"].ToString(), (string)Session["ApplyPeriod"], drpInteviewMonth.SelectedValue, drpInteviewday.SelectedValue, drpHH.SelectedValue, drpMM.SelectedValue);
            }
        }

        public void BindMonth()
        {
            drpInteviewMonth.Items.Clear();
            ListItem list2 = new ListItem("", "");
            drpInteviewMonth.Items.Add(list2);
            for (int i = 1; i <= 12; i++)
            {
                ListItem list1 = new ListItem(i.ToString(), i.ToString());
                drpInteviewMonth.Items.Add(list1);
            }
        }


        public void bindTime()
        {
            BindMonth();
            BindMM();
            bindHH();
            BindDay();
        }

        public void BindDay()
        {
            drpInteviewday.Items.Clear();
            ListItem list2 = new ListItem("", "");
            drpInteviewday.Items.Add(list2);
            for (int i = 1; i <= 31; i++)
            {
                ListItem list1 = new ListItem(i.ToString(), i.ToString());
                drpInteviewday.Items.Add(list1);
            }
        }

        public void BindMM()
        {
            drpMM.Items.Clear();
            ListItem list2 = new ListItem("", "");
            drpMM.Items.Add(list2);
            for (int i = 0; i < 60; i++)
            {
                ListItem list1 = new ListItem(i.ToString(), i.ToString());
                drpMM.Items.Add(list1);
            }
        }

        public void bindHH()
        {
            drpHH.Items.Clear();
            ListItem list2 = new ListItem("", "");
            drpHH.Items.Add(list2);
            for (int i = 0; i < 24; i++)
            {
                ListItem list1 = new ListItem(i.ToString(), i.ToString());
                drpHH.Items.Add(list1);
            }
        }

        protected void butSave_Click(object sender, EventArgs e)
        {
            SaveInterviewTime();
        }
    }
}
